import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;


public class Output {
	
	private PrintWriter out;
	
	

	public Output(HttpServletResponse response){
		
		
		response.setContentType("application/json");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST");
        response.setHeader("Access-Control-Allow-Headers", "Content-Type");
        response.setHeader("Access-Control-Max-Age", "86400");
		
        try {
			out= response.getWriter();
			//this.servlet;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public <T> void format(T outClassformatter){
		//Gson gson = new GsonBuilder().disableHtmlEscaping().create();
		Gson gson = new Gson();
		String json = gson.toJson(outClassformatter);
		
		
		this.out.print(json);
		this.out.flush();
	}
	

}
